import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },

  {
    path: '/project-manage',
    component: Layout,
    redirect: '/project-manage/p',
    name: '标准管理',
    meta: {
      title: '标准管理',
      icon: 'nested'
    },
    // children: [
    //   {
    //     path: 'p',
    //     name: '标准管理',
    //     component: () => import('@/views/project-manage/p/index'),
    //     meta: { title: '标准管理' },
        children: [
          {
            path: 'p1',
            name: 'xx标准',
            component: () => import('@/views/project-manage/p/p1'),
            meta: { title: 'xx标准', icon: 'dashboard'  }
          },
          {
            path: 'p2',
            name: 'xx项目',
            component: () => import('@/views/project-manage/p/p2'),
            meta: { title: 'xx项目', icon: 'dashboard'  }
          },
          {
            path: 'p3',
            name: '设备管理',
            component: () => import('@/views/project-manage/p/p3'),
            meta: { title: '设备管理', icon: 'dashboard'  }
          },
          {
            path: 'p4',
            name: '添加设备',
            component: () => import('@/views/project-manage/p/p4'),
            meta: { title: '添加设备', icon: 'dashboard'  }
          },
          {
            path: 'p5',
            name: '设备方案',
            component: () => import('@/views/project-manage/p/p5'),
            meta: { title: '设备方案', icon: 'dashboard'  }
          },
          {
            path: 'p6',
            name: '添加方案',
            component: () => import('@/views/project-manage/p/p6'),
            meta: { title: '添加方案', icon: 'dashboard'  }
          },
        ]
    //   },
    // ]
  },

  {
    path: "/check_project",
    component: Layout,
    children: [
      {
        path: "check_project1", // 使用相对路径
        component: () => import("@/views/project-manage/check_project1.vue"),
        name: "check_project1",
        hidden: true,
        meta: { title: "模块选择" },
      },
    ],
  },

  {
    path: "/message-manage",
    component: Layout,
    children: [
      {
        path: "message",
        name: "留言管理",
        component: () => import("@/views/message-manage/message"),
        meta: { title: "留言管理", icon: "form" },
      },
    ],
  },

  {
    path: "/list-manage",
    component: Layout,
    redirect: "/list-manage/list",
    name: "清单管理",
    meta: {
      title: "清单管理",
      icon: "nested",
    },
    children: [
      {
        path: "list",
        name: "清单管理",
        component: () => import("@/views/list-manage/list"),
        meta: { title: "清单管理 1", icon: "nested" },
      },
      {
        path: "user-info",
        component: () => import("@/views/list-manage/info/user-info.vue"),
        name: "user-info",
        meta: { title: "人员信息" },
          children: [
           {
            path: "modify", // 使用相对路径
            component: () =>
               import("@/views/list-manage/info/modify/modify.vue"),
            name: "modify",
            meta: { title: "修改信息" },
          },
        ],
      },
      {
        path: "menu2",
        component: () => import("@/views/list-manage/modify-pw.vue"),
        name: "modify-pw",
        meta: { title: "修改密码" },
      },
    ],
  },

  {
    path: "/nested",
    component: Layout,
    redirect: "/nested/menu1",
    name: "Nested",
    meta: {
      title: "Nested",
      icon: "nested",
    },
    children: [
      {
        path: "menu1",
        // component: () => import("@/views/nested/menu1/index"), // Parent router-view
        name: "Menu1",
        meta: { title: "Menu1" },
        children: [
          {
            path: "menu1-1",
            component: () => import("@/views/nested/menu1/menu1-1/index"),
            name: "Menu1-1",
            meta: { title: "Menu1-1" },
          },
          {
            path: "menu1-2",
            component: () => import("@/views/nested/menu1/menu1-2/index"),
            name: "Menu1-2",
            meta: { title: "Menu1-2" },
            children: [
              {
                path: "menu1-2-1",
                component: () =>
                  import("@/views/nested/menu1/menu1-2/menu1-2-1/index"),
                name: "Menu1-2-1",
                meta: { title: "Menu1-2-1" },
              },
              {
                path: "menu1-2-2",
                component: () =>
                  import("@/views/nested/menu1/menu1-2/menu1-2-2/index"),
                name: "Menu1-2-2",
                meta: { title: "Menu1-2-2" },
              },
            ],
          },
          {
            path: "menu1-3",
            component: () => import("@/views/nested/menu1/menu1-3/index"),
            name: "Menu1-3",
            meta: { title: "Menu1-3" },
          },
        ],
      },
      {
        path: "menu2",
        component: () => import("@/views/nested/menu2/index"),
        name: "Menu2",
        meta: { title: "menu2" },
      },
    ],
  },

  {
    path: '/people',
    component: Layout,
    redirect: 'people',
    name: '人员界面',
    meta: {
      title: '人员界面',
      icon: 'nested'
    },
    children: [
      {
        path: 'people',
        name: '人员界面',
        component: () => import('@/views/people/people.vue'),
        meta: { title: '人员界面', icon: 'nested' }
      },
      {
        path: 'train',
        component: () => import('@/views/people/train_manage/train.vue'),
        name: 'train',
        meta: { title: '培训管理' },

      },
      {
        path: 'leave-words',
        component: () => import('@/views/people/train_manage/leave-words.vue'),
        name: 'leave-words',
        meta: { title: '留言管理' }
      },

      {
        path: 'audit',
        component: () => import('@/views/people/train_manage/audit.vue'),
        name: 'audit',
        meta: { title: '授权审核' }
      },

      {
        path: 'certificate',
        component: () => import('@/views/people/train_manage/certificate.vue'),
        name: 'certificate',
        meta: { title: '证书界面' }
      },
    ]
  },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
